package com.soviet.boot.business.system.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import com.soviet.boot.common.annotation.ResultAndLog;
import com.soviet.boot.common.base.vo.IdsRequestVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.soviet.boot.business.system.entity.SysRole;
import com.soviet.boot.business.system.service.ISysRoleService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Dave
 * @since 2021/08/01
 */
@RestController
@AllArgsConstructor
@ResultAndLog
@RequestMapping("/system/sys-role")
public class SysRoleController {
    private final ISysRoleService sysRoleService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return
     */
    @GetMapping("/page")
    public Object getSysRolePage(Page<SysRole> page, SysRole query, @RequestParam(value = "dateRange", required = false) String dateRange) {
        return sysRoleService.page(page, new LambdaQueryWrapper<>(query));
    }

    /**
     * 通过id查询
     *
     * @param id id
     * @return Object
     */
    @GetMapping("/info")
    public Object getById(@RequestParam("id") Long id) {
        return sysRoleService.getById(id);
    }

    /**
     * 新增
     *
     * @param sysRole
     * @return Object
     */
    @PostMapping("/add")
    public Object save(@RequestBody SysRole sysRole) {
        return sysRoleService.save(sysRole);
    }

    /**
     * 修改
     *
     * @param sysRole
     * @return Object
     */
    @PostMapping("/update")
    public Object updateById(@RequestBody SysRole sysRole) {
        return sysRoleService.updateById(sysRole);
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return Object
     */
    @PostMapping("/delete")
    public Object removeById(@RequestParam Long id) {
        return sysRoleService.removeById(id);
    }


    /**
     * 批量删除
     *
     * @param body ids
     * @return Object
     */
    @PostMapping("/batchDelete")
    public Object removeByIds(@RequestBody IdsRequestVO body) {
        return sysRoleService.removeByIds(body.getIds());
    }

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/listAll")
    public Object listAll() {
        return sysRoleService.list();
    }

}




